<?php
namespace App\Model;
use PhalApi\Model\NotORMModel as NotORM;

class Wall extends NotORM {
	/* 我的背景墙 */
	public function myWall($uid) {
		
		$info=\PhalApi\DI()->notorm->backwall
				->select('*')
				->where('uid=?',$uid)
                ->order('type desc')
				->fetchAll();

		return $info;
	}
    
    /* 封面信息 */
	public function getCover($uid) {
		
		$info=\PhalApi\DI()->notorm->backwall
				->select('*')
				->where('uid=? and type=-1',$uid)
				->fetchOne();

		return $info;
	}

    /* 背景信息 */
	public function getWall($id) {
		
		$info=\PhalApi\DI()->notorm->backwall
				->select('*')
				->where('id=?',$id)
				->fetchOne();

		return $info;
	}
    
    /* 视频数量 */
	public function getWallVideo($uid,$id=0) {
		
		$nums=\PhalApi\DI()->notorm->backwall
				->where('uid=? and type=1 and id!=?',$uid,$id)
				->count();

		return (string)$nums;
	}
    
    /* 背景墙数量 */
	public function getWallNums($uid,$id=0) {
		
		$nums=\PhalApi\DI()->notorm->backwall
				->where('uid=? and type!=-1 and id!=?',$uid,$id)
				->count();

		return (string)$nums;
	}
    
	/* 新加 */
	public function setWall($data) {

		$result= \PhalApi\DI()->notorm->backwall->insert($data);

		return $result;
	}
    
    /* 更新 */
    public function upWall($id,$data) {

		$result= \PhalApi\DI()->notorm->backwall
                    ->where('id=?',$id)
                    ->update($data);

		return $result;
	}

    /* 删除 */
    public function delWall($uid,$id=0) {

        if($id){
            $result= \PhalApi\DI()->notorm->backwall
                    ->where('uid=? and type != -1 and id=?',$uid,$id)
                    ->delete();
        }else{
            $result= \PhalApi\DI()->notorm->backwall
                    ->where('uid=?',$uid)
                    ->delete();
        }
		
		return $result;
	}

}
